// 用户名非空验证
const nonNullUserName = () => {
    if ($('.username').val() == '') {
        $('.usernameTips').html('用户名不能为空')
        return false
    } else {
        $('.usernameTips').html('')
        return true
    }
}

// 密码非空验证
const nonNullPassword = () => {
    if ($('.password').val() == '') {
        $('.passwordTips').html('密码不能为空')
        return false
    } else {
        $('.passwordTips').html('')
        return true
    }
}

// 密码格式验证
const strengthPassword = () => {
    // 密码必须是大写字母开头，字母和数字的组合，至少8位
    let passwordReg = /^[A-Z][a-zA-Z0-9]{7,}$/
    if (!passwordReg.test($('.password').val())) {
        $('.passwordTips').html('密码必须是大写字母开头，字母和数字的组合，至少8位')
        return false
    } else {
        $('.passwordTips').html('')
        return true
    }
}


$('.loginBtn').click(function () {
    let isNonNullUserName = nonNullUserName()
    let isNonNullPassword = nonNullPassword()
    if (!isNonNullUserName || !isNonNullPassword) {
        return
    }

    let isStrengthPassword = strengthPassword()
    if (!isStrengthPassword) {
        return
    }

    alert('注册成功！')
    let userList=[{username:$('.username').val(),password:$('.password').val()}]
    localStorage.setItem('USERS',JSON.stringify(userList))
    location.href="./login.html"

})

